package org.lanqiao.tjut.erfenfa;

import java.util.Scanner;

public class erfenfa {

	public static void main(String[] args) {
		int[] arr = { 2, 4,4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 };

		int low = 0;
		int high = arr.length ;
		int a;
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个数");
		a = input.nextInt();
		for (int i = 0; i < Math.log(arr.length)+1; i++) {
			int temp = (low + high) / 2;
			if (a <= arr[temp]) {
				high = temp-1;
			} else {
				low = temp+1;
			}

			if (a == arr[temp]) {
				System.out.println("找到该数,第"+(i+1)+"二分法找到，是第" + (temp+1)  + "个数");
				return;
			}
		}
		System.out.println("找不到该数");

	}

}
